<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="app">
        <input type="text" v-model='fname'>
        <button @click='add'>添加</button>
        <button @click='del'>删除</button>
        <button @click='change'>替换</button>
        <ul>
            <li :key='index' v-for='(item,index) in list'>{{item}}</li>
        </ul>
    </div>
    <script src="js/vue.js"></script>
    <script>
        /*
              Vue数组操作
              1、变异方法：会影响数组的原始数据的变化。
              2、替换数组：不会影响原始的数组数据，而是形成一个新的数组。
            */
        var vm = new Vue({
            el: '#app',
            data: {
                fname: '',
                list: ['apple', 'orange', 'banana']
            },
            methods: {
                add: function() {
                    this.list.push(this.fname);
                },
                del: function() {
                    this.list.pop();

                },
                change: function() {
                    this.list = this.list.slice(0, 2);
                }
            }
        })
    </script>
</body>

</html>